// 自定义元数据工具类
/*
var CustomMetaData = function (){
    let inited = false;
    let startSymbol = '';
    let endSymbol = '';

    this.init = function(startSymbol,endSymbol){
        this.startSymbol = startSymbol;
        this.endSymbol = endSymbol;
        this.inited = true;
    }

    this.printSymbol = function(){
        console.log(`startSymbol:${this.startSymbol},endSymbol:${this.endSymbol}`);
    }
}();
 */

class CustomMetaData {
    startSymbol;endSymbol;inited;
    // 构造函数
    constructor(startSymbol, endSymbol) {
        this.startSymbol = startSymbol;
        this.endSymbol = endSymbol;
        this.inited = true;
    }
    print() {
        console.log(`startSymbol:${this.startSymbol},endSymbol:${this.endSymbol}`);
    }
    // 获取最后一个单元数据，带有起始、终止符号
    getLastMetaData(data){
        if(!this.inited){
            console.log('请初始化之后再使用本函数！');
            return
        }
        if(!data || data.length === 0) return '';
        const lastStartIndex = data.lastIndexOf(this.startSymbol);
        const lastEndIndex = data.lastIndexOf(this.endSymbol);
        if(lastStartIndex < 0 || lastEndIndex < 0) return '';
        if(lastEndIndex <= lastStartIndex) return '';
        return data.substring(lastStartIndex,lastEndIndex+1);
    }
    // 返回最后一个单元数据，排除起始、终止符号
    getLastMetaDataPure(data){
        const meta = this.getLastMetaData(data);
        return meta.substring(1,meta.length - 1);
    }
}